package com.cy.springbootemep.service.serviceimpl;

import com.cy.springbootemep.dao.EmpDao;
import com.cy.springbootemep.handlerException.HasNoDataException;
import com.cy.springbootemep.pojo.Emp;
import com.cy.springbootemep.service.EmpService;
import com.cy.springbootemep.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmpServiceimpl implements EmpService {

    @Autowired
    EmpDao empDao;

    @Override
    public List<Emp> selec() {
        return empDao.sele();
    }

    @Override
    public List<Emp> seleall(Integer id) {
        int length = new JsonResult(empDao.seleall(id)).getData().toString().length();
        if (id == null) throw new RuntimeException("id为空");
        if (length <= 2) throw new HasNoDataException("查询为空");
        return empDao.seleall(id);
    }

    @Override
    public List<Emp> seleall2(Integer[] ids) {
        int length = new JsonResult(empDao.seleids(ids)).getData().toString().length();
        ;
        if (ids == null) throw new RuntimeException("为输入id");

        return empDao.seleids(ids);
    }

    @Override
    public List<Emp> seleall3(Emp emp) {
        int length = new JsonResult(empDao.seleti(emp)).getData().toString().length();
        if (length <= 2) throw new HasNoDataException("查询为空");
        return empDao.seleti(emp);
    }

    @Override
    public int upda(Emp emp) {
        return empDao.upd(emp);
    }

    @Override
    public int inser(Emp emp) {
        return empDao.inse(emp);

    }

    @Override
    public int de(Integer[] ids) {
        return empDao.del(ids);
    }
}
